#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
int n;
const int mod = 1e9 + 7, N = 10010;
int a[N];
LL dp[N];
// 首先，n^2的算法可以
// 对于一段区间，如果区间中的数是连续的，一定有max - min = j - i
int main()
{
  cin >> n;
  for(int i = 1; i <= n; ++i) cin >> a[i];
  dp[0] = dp[1] = 1;
  for(int i = 2; i <= n; ++i)
  {
    int maxv = a[i], minv = a[i];
    for(int j = i; j > 0; --j)
    {
      maxv = max(maxv, a[j]);
      minv = min(minv, a[j]);
      if(maxv - minv == i - j)
        dp[i] = (dp[i] + dp[j - 1]) % mod;
    }
  }
  // for(int i = 0; i <= n; ++i) cout << dp[i] << ' ';
  // cout << endl;
  cout << dp[n] << endl;
  return 0;
}